//
//  ProduceLongTimeView.m
//  ZJControlsClass
//
//  Created by mac on 2024/11/29.
//

#import "ProduceLongTimeView.h"
#import "ProduceLongTimeCollectionViewCell.h"


@interface ProduceLongTimeView ()
//<UICollectionViewDelegate,UICollectionViewDataSource>

@property (nonatomic,strong) UIImageView * follewImg;
@property (nonatomic,strong) UIImageView * iconImg;
//@property (nonatomic,strong) UICollectionView * collectionView;
@property (nonatomic,strong) NSMutableArray * dataSource;

@property (nonatomic,strong) UILabel * nameLabel;
@property (nonatomic,strong) UILabel * codeLabel;
@property (nonatomic,strong) UILabel * canplyLabel;
@property (nonatomic,strong) UILabel * timeLabel;
@property (nonatomic,strong) UILabel * numberLabel;

@property (nonatomic, strong) UIStackView *optionsStackView;  // 用于存放选项的容器

@end






@implementation ProduceLongTimeView


- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if (self){
        
        self.backgroundColor = COLOR_RGB(50, 113, 237);

        [self configUI];
        
        
    }
    
    return self;
    
}

-(void)setParamer:(NSMutableDictionary *)paramer{
    _paramer = paramer;
    
    [self.iconImg sd_setImageWithURL:[NSURL URLWithString:self.paramer[@"photo"]] placeholderImage:nil];
    self.dataSource = [NSMutableArray arrayWithArray:paramer[@"passageAreaList"]];
//    [self.collectionView reloadData];
    
    self.nameLabel.text = [NSString stringWithFormat:@"姓名：%@",self.paramer[@"nickname"]];
    self.codeLabel.text = [NSString stringWithFormat:@"编号：%@",self.paramer[@"idCode"]];
    self.canplyLabel.text = [NSString stringWithFormat:@"单位：%@",self.paramer[@"unitName"]];
    self.timeLabel.text = [NSString stringWithFormat:@"期限：%@",self.paramer[@"expiryDate"]];
    self.numberLabel
        .text = [NSString stringWithFormat:@"分数：%@分",self.paramer[@"score"]];
    
        for (UIView *view in self.optionsStackView.arrangedSubviews) {
            [view removeFromSuperview];
        }
        
        // 添加新的选项
    for (NSDictionary *option in self.dataSource) {
            UIView *container = [[UIView alloc] init];
            container.backgroundColor = [UIColor whiteColor];
            container.layer.borderWidth = 1;
            container.layer.borderColor = [UIColor brownColor].CGColor;
            
            UILabel *label = [[UILabel alloc] init];
            label.text = option[@"code"];
            label.textColor = [UIColor brownColor];
            label.textAlignment = NSTextAlignmentCenter;
            [container addSubview:label];
            [self.optionsStackView addArrangedSubview:container];
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.edges.equalTo(container);
            }];
            
            [container mas_makeConstraints:^(MASConstraintMaker *make) {
                make.width.height.mas_equalTo(28.5);
            }];
            
           
        }
    
    
}




-(void)configUI{
    
    [self addSubview:self.follewImg];
    [self.follewImg addSubview:self.iconImg];
//    [self.follewImg addSubview:self.collectionView];
    [self.follewImg addSubview:self.nameLabel];
    [self.follewImg addSubview:self.codeLabel];
    [self.follewImg addSubview:self.canplyLabel];
    [self.follewImg addSubview:self.timeLabel];
    [self.follewImg addSubview:self.numberLabel];
    
    self.optionsStackView = [[UIStackView alloc] init];
        self.optionsStackView.axis = UILayoutConstraintAxisVertical;
        self.optionsStackView.spacing = 3.5;
        self.optionsStackView.alignment = UIStackViewAlignmentCenter;
        self.optionsStackView.distribution = UIStackViewDistributionEqualSpacing;
        [self.follewImg addSubview:self.optionsStackView];

    // 布局约束
        [self.optionsStackView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.iconImg.mas_left).offset(-29);
            make.centerY.equalTo(self.iconImg);
        }];
    
    [self.follewImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.top.equalTo(self).with.offset(ALIGN_HEIGHT_PT(30));
        make.height.equalTo(@(ALIGN_HEIGHT_PT(490)));
    }];
    
    [self.iconImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.follewImg).with.offset(ALIGN_WIDTH_PT(110));
        make.top.equalTo(self.follewImg).with.offset(ALIGN_HEIGHT_PT(113));
        make.size.equalTo(@(CGSizeMake(ALIGN_WIDTH_PT(134), ALIGN_HEIGHT_PT(187))));
    }];
    
//    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.right.equalTo(self.iconImg.mas_left).with.offset(-ALIGN_WIDTH_PT(29));
//        make.top.equalTo(self.iconImg.mas_top);
//        make.bottom.equalTo(self.iconImg.mas_bottom);
//        make.size.equalTo(@(CGSizeMake(ALIGN_WIDTH_PT(28.5), ALIGN_HEIGHT_PT(187))));
//    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.optionsStackView.mas_left);
        make.top.equalTo(self.iconImg.mas_bottom).with.offset(ALIGN_HEIGHT_PT(22));
    }];
    
    
    [self.codeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.optionsStackView.mas_left);
        make.top.equalTo(self.nameLabel.mas_bottom).with.offset(ALIGN_HEIGHT_PT(5));
    }];
    
    [self.canplyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.optionsStackView.mas_left);
        make.top.equalTo(self.codeLabel.mas_bottom).with.offset(ALIGN_HEIGHT_PT(5));
    }];
    
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.optionsStackView.mas_left);
        make.top.equalTo(self.canplyLabel.mas_bottom).with.offset(ALIGN_HEIGHT_PT(5));
    }];
    
    [self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.optionsStackView.mas_left);
        make.top.equalTo(self.timeLabel.mas_bottom).with.offset(ALIGN_HEIGHT_PT(5));
    }];
    
    
    
    
        
}
//
//#pragma mark -- UICollectionViewDelegate,UICollectionViewDataSource
//-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
//    return 1;
//}
//-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
//    return self.dataSource.count;
//}
//-(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
//
//        
//    ProduceLongTimeCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ProduceLongTimeCollectionViewCell" forIndexPath:indexPath];
//    cell.areaLabel.text = self.dataSource[indexPath.row][@"code"];
//        
//    return cell;
//    
//}
//
//
//#pragma mark - item宽高
//- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
//
//    return CGSizeMake(ALIGN_WIDTH_PT(28.5), ALIGN_WIDTH_PT(28.5));
//    
//}
//
//#pragma mark - <UICollectionViewDelegateFlowLayout>
//#pragma mark - X间距
//- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
//    return  ALIGN_WIDTH_PT(0);
//}
//#pragma mark - Y间距
//- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
//    return  ALIGN_WIDTH_PT(3.5);
//}
//



#pragma mark -- 懒加载
-(UIImageView *)follewImg{
    if (!_follewImg){
        _follewImg = [UIImageView new];
        _follewImg.image = [UIImage imageNamed:@"长期通行证"];
    }
    return _follewImg;
}

-(UIImageView *)iconImg{
    if (!_iconImg){
        _iconImg = [UIImageView new];
    }
    return _iconImg;
}

//-(UICollectionView *)collectionView{
//    if (!_collectionView) {
//        UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new];
//        layout.minimumLineSpacing = 0;
//        layout.minimumInteritemSpacing = 0;
//        layout.scrollDirection = UICollectionViewScrollDirectionVertical;
//        // 设置cell上下居中对齐
//        layout.sectionInset = UIEdgeInsetsMake(ALIGN_WIDTH_PT(3.5), 0, ALIGN_WIDTH_PT(3.5), 0);
//        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
//        _collectionView.delegate = self;
//        _collectionView.dataSource = self;
//        _collectionView.backgroundColor = [UIColor clearColor];
//        
//        //cell
//        [_collectionView registerClass:[ProduceLongTimeCollectionViewCell class] forCellWithReuseIdentifier:@"ProduceLongTimeCollectionViewCell"];
//
//    }
//    return _collectionView;
//}

-(UILabel *)nameLabel{
    if (!_nameLabel){
        _nameLabel = [UILabel new];
        _nameLabel.textColor = [UIColor blackColor];
        _nameLabel.font = FONT16;
        _nameLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _nameLabel;
}

-(UILabel *)codeLabel{
    if (!_codeLabel){
        _codeLabel = [UILabel new];
        _codeLabel.textColor = [UIColor blackColor];
        _codeLabel.font = FONT16;
        _codeLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _codeLabel;
}
-(UILabel *)canplyLabel{
    if (!_canplyLabel){
        _canplyLabel = [UILabel new];
        _canplyLabel.textColor = [UIColor blackColor];
        _canplyLabel.font = FONT16;
        _canplyLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _canplyLabel;
}
-(UILabel *)timeLabel{
    if (!_timeLabel){
        _timeLabel = [UILabel new];
        _timeLabel.textColor = [UIColor blackColor];
        _timeLabel.font = FONT16;
        _timeLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _timeLabel;
}
-(UILabel *)numberLabel{
    if (!_numberLabel){
        _numberLabel = [UILabel new];
        _numberLabel.textColor = [UIColor blackColor];
        _numberLabel.font = FONT16;
        _numberLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _numberLabel;
}



@end
